package com.zs.blog.controller;

import com.zs.blog.model.ResponseResult;
import com.zs.blog.model.dto.ApplyFriendLinkDTO;
import com.zs.blog.model.dto.AuditFriendLinkDTO;
import com.zs.blog.model.dto.FriendLinkSearchDTO;
import com.zs.blog.model.dto.RemoveFriendLinkDTO;
import com.zs.blog.model.vo.FriendLinkListVO;
import com.zs.blog.model.vo.PageInfoVO;
import com.zs.blog.service.IFriendLinkService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

/**
 * @Title: FriendLinkController
 * @Author zs
 * @Package com.zs.blog.controller
 * @Date 2025/6/3 22:20
 * @description: 友链接口层
 */
@RestController
public class FriendLinkController {

    public IFriendLinkService friendLinkService;

    public FriendLinkController(IFriendLinkService friendLinkService) {
        this.friendLinkService = friendLinkService;
    }


    @GetMapping("/admin/link/list")
    @Operation(summary = "获取分页的友链列表")
    public ResponseResult<PageInfoVO<FriendLinkListVO>> listFriendLink(Long pageNum, Long pageSize) {
        PageInfoVO<FriendLinkListVO> friendLinkList = friendLinkService.listFriendLink(pageNum, pageSize);
        return ResponseResult.success(friendLinkList);
    }

    @PostMapping("/admin/link/delete")
    @Operation(summary = "下架友链")
    public ResponseResult<?> deleteFriendLink(@RequestBody RemoveFriendLinkDTO removeFriendLinkDTO) {
        friendLinkService.deleteFriendLink(removeFriendLinkDTO);
        return ResponseResult.success();
    }

    @PostMapping("/admin/link/search")
    @Operation(summary = "通过搜索条件查询分页的友链列表")
    public ResponseResult<PageInfoVO<?>> listFriendLinkBySearchCondition(@RequestBody FriendLinkSearchDTO friendLinkSearchDTO) {
        PageInfoVO<FriendLinkListVO> listFriendLink = friendLinkService.listFriendLinkBySearchCondition(friendLinkSearchDTO);
        return ResponseResult.success(listFriendLink);
    }

    @PostMapping("/admin/link/audit")
    @Operation(summary = "审核友链")
    public ResponseResult<?> auditFriendLink(@RequestBody AuditFriendLinkDTO auditFriendLinkDTO) {
        friendLinkService.auditFriendLink(auditFriendLinkDTO);
        return ResponseResult.success();
    }

    @PostMapping("/portal/link/apply")
    @Operation(summary = "申请友链")
    public ResponseResult<?> applyFriendLink(@RequestBody ApplyFriendLinkDTO applyFriendLinkDTO) {
        friendLinkService.applyFriendLink(applyFriendLinkDTO);
        return ResponseResult.success();
    }

}
